/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package examples;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextField;

/**
 *
 * @author Kelly Ruiz
 */
public class TestCheckBox extends JFrame {

    
    private JTextField campoTexto;
    public JCheckBox negritaCheck;
    public JCheckBox cursivaCheck;
    
    public TestCheckBox(){
        
        super("Prueba de Verificación");
        setLayout(new FlowLayout());
        
        campoTexto = new JTextField("Mostrando como cambia la letra", 20);
        campoTexto.setFont(new Font("Serif", Font.PLAIN, 14));
        add(campoTexto);
                
        negritaCheck = new JCheckBox("Negrita");
        cursivaCheck = new JCheckBox("Cursiva");
        
        add(negritaCheck);
        add(cursivaCheck);
        
        
        ManejadorLetras manejador = new ManejadorLetras();
        negritaCheck.addItemListener(manejador);
        cursivaCheck.addItemListener(manejador);
   
    }
    

class ManejadorLetras implements ItemListener{
    
    private int negrita = Font.PLAIN;
    private int cursiva = Font.PLAIN;
    
    //@Override
    public void itemStateChanged(ItemEvent e) {
       //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        if (e.getSource() == negritaCheck){
            if (negritaCheck.isSelected()){
                negrita = Font.BOLD;
            }else{
                negrita = Font.PLAIN;
            }
        }
        
        if (e.getSource() == cursivaCheck){
            if(cursivaCheck.isSelected()){
                cursiva = Font.ITALIC;
            }else{
                cursiva = Font.PLAIN;
            }
        }
        
        Font a = new Font("Serif", negrita + cursiva, 15);
        campoTexto.setFont(a);
               
    }

   }
}

